Skip to content

Labels centred on their capitals: the kit's pk-label, and a renderer check - #190

Merged
agorischek merged 3 commits into
mainfrom
agorischek/cap-labels
Nov 23, 2026
Merged

agorischek merged 3 commits into
mainfrom
agorischek/cap-labels

Conversation

@agorischek

@agorischek agorischek commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Polish step (c): text centred on its capitals in every chip, bar and button, as a kit primitive with a renderer check.

Why

A line of text centred by its line box sits a little high or low in its chip, bar or button. How far depends on how the font's ascent, descent and cap height compare, and it differs between Chromium (whole-pixel metrics) and WebKit (fractional ones). The rule is the capital-E test: a capital E has as much room above it as below it.

Kit: pk-label

  • pk-label trims the text box to the capitals and the alphabetic baseline (text-box: trim-both cap alphabetic), then pads it back to its line height. The box keeps its size, and whatever centres it centres the capitals.
  • Room of its own goes in --pk-label-inset.
  • A label holding one identifier takes the identifier's font.
  • Without text-box support, it is an ordinary line.
  • The kit uses it in change pills and value changes, badges, status words and status tabs, group titles and meta, and the graph footer's buttons.

Check: label-centring (probe call labels)

  • What it measures: every HTML chip, bar or button: up to 48px tall, painting a background or edges above and below, with one line of its own text. The room above the capitals and below the baseline must match within half a pixel.
  • Where the metrics come from: each font's ascent and 1cap, laid out once on a hidden line. Canvas metrics don't work: WebKit rounds them, but not its layout, and glyph ink differs between engines. On trimmed labels the model matches the trimmed box within 0.01px in both engines.
  • Special cases: in a collapsed table, each rule counts half to each cell. A box stretched by its row past its own line, such as a line number beside a wrapped line, isn't a label.
  • Spacing: spacing counts only a trimmed label's inset as spacing; the rest of its padding comes from the font.
  • Why it isn't a pixel check: glyph baselines snap to device pixels and antialiasing counts partially, so pixels read ±0.35px. A pixel assertion would be flaky, so the check is structural. labels.spec shows the probe works: it finds the original violations once the trim is undone.

Violations found and fixed

Measured on chromium-desktop, webkit-desktop and chromium-mobile:

  • Kit: group headers, change pills, status tabs.
  • runtime-policy: chips (now centred, not baseline-aligned, so a taller mobile chip stays centred), head rows, warnings.
  • database: headers, tags, value pills (an identifier inside a sans label), and column, key and enum rows (now centred in the 31px under their top rule).
  • text-diff: line numbers, marks, text, captions.
  • agentic-workflows:
    • Matrix cells: a table cell centres to whole pixels, so the mark now fills the row.
    • The stale-lock pill: its icon set the line's baseline, so the text sat 2px high.
  • code-statistics: pills.
  • api: signatures, and their +/− mark, which WebKit placed on the trimmed line's top.
  • gallery: revision buttons.
  • graph: footer buttons.

After the fixes, checks.spec passes 26/26 on all three projects.

Before and after (2×)

Labels before and after, light
Labels before and after, dark

The differences are fractions of a pixel by design. In the pills, the database header and the captions, the capitals now sit evenly between the edges.

Follow-ups (CI)

  • Kit relationship rows: EntityCard relationship rows are labels too. The CLI starter renderer draws them, and no harness scenario did.
  • Main text: label-centring centres a box on its main text, meaning the runs in its largest font size. A title outweighs its smaller meta, and a database name outweighs its key's smaller mono, which Linux's fonts set lower.
  • Removed identifier-font rule: a kit rule gave a label holding one identifier that identifier's font. It also matched words containing a code span (text nodes aren't children), which set runtime-policy warning notes in mono. It is now database's own rule.
  • api browser spec: reads a signature's tone without pk-label.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active issues cause mixed prose to inherit identifier typography and scaled labels to be measured with inconsistent coordinates, requiring fixes to font targeting and measurement logic.

2 open issues
What changed in this PR

This PR adds the renderer kit’s pk-label primitive to centre text on its capitals, applies it across built-in renderers, and introduces a structural check for label alignment.

Changes:

  • Adds shared label trimming, font handling and inset styles.
  • Updates renderer labels, chips, headers and buttons, with matching markup assertions.
  • Adds the labels probe, label-centring check, regression coverage and documentation.
File Description
packages/​renderers/​text-diff/​test/​view.test.mjs Updates label markup assertions.
packages/​renderers/​text-diff/​src/​view.tsx Applies labels to gutters, text and captions.
packages/​renderers/​testing/​test/​helpers.test.mjs Tests check registration and failure reporting.
packages/​renderers/​testing/​src/​types.ts Defines label probe and check types.
packages/​renderers/​testing/​src/​probe.ts Registers the labels probe.
packages/​renderers/​testing/​src/​measure/​styles/​box.ts Excludes font-derived padding from spacing checks.
packages/​renderers/​testing/​src/​measure/​labels.ts Measures capital alignment against label surfaces.
packages/​renderers/​testing/​src/​measure.ts Exports label measurement.
packages/​renderers/​testing/​src/​checks/​runner.ts Registers the label check.
packages/​renderers/​testing/​src/​checks/​labels.ts Reports and groups alignment failures.
packages/​renderers/​testing/​src/​checks/​catalog.ts Adds check title and description.
packages/​renderers/​testing/​README.md Documents alignment and spacing checks.
packages/​renderers/​runtime-policy/​test/​runtime-policy.test.mjs Updates chip and heading assertions.
packages/​renderers/​runtime-policy/​src/​styles.css Centres chips and adjusts heading padding.
packages/​renderers/​runtime-policy/​src/​row.tsx Labels headings and warnings.
packages/​renderers/​runtime-policy/​src/​chips.tsx Labels chip signs, prefixes and text.
packages/​renderers/​kit/​test/​table.test.mjs Updates value-pill assertions.
packages/​renderers/​kit/​test/​group.test.mjs Updates group label assertions.
packages/​renderers/​kit/​test/​diff.test.mjs Updates change-pill assertions.
packages/​renderers/​kit/​styles/​status.css Defines the shared label primitive.
packages/​renderers/​kit/​styles/​layout.css Preserves group label insets.
packages/​renderers/​kit/​styles/​diff.css Avoids trimming containers of value-change pills.
packages/​renderers/​kit/​src/​react/​status-tab.tsx Wraps status-tab text in labels.
packages/​renderers/​kit/​src/​react/​layout-components.tsx Labels group titles and metadata.
packages/​renderers/​kit/​src/​react/​graph-canvas/​graph-footer.tsx Labels footer button text.
packages/​renderers/​kit/​src/​react/​diff-components.tsx Labels values and change-pill content.
packages/​renderers/​kit/​src/​react/​components.tsx Labels badges and status words.
packages/​renderers/​harness/​browser/​labels.spec.ts Tests detection after disabling label trimming.
packages/​renderers/​gallery/​src/​view.tsx Labels revision button text.
packages/​renderers/​gallery/​src/​styles.css Centres revision button contents.
packages/​renderers/​database/​test/​transition.test.mjs Updates status and identifier assertions.
packages/​renderers/​database/​src/​tags.tsx Labels measured and displayed tags.
packages/​renderers/​database/​src/​table.tsx Labels names, types, keys and headings.
packages/​renderers/​database/​src/​styles.css Enables trimming and adjusts row padding.
packages/​renderers/​code-statistics/​test/​statistics.test.mjs Updates status-word markup assertion.
packages/​renderers/​api/​test/​api.test.mjs Updates signature and marker assertions.
packages/​renderers/​api/​src/​styles.css Sets signature insets and marker positioning.
packages/​renderers/​api/​src/​signature-view.tsx Labels signatures and change markers.
packages/​renderers/​agentic-workflows/​src/​styles.css Adjusts lock alignment and matrix glyph centring.
packages/​renderers/​agentic-workflows/​src/​matrix.tsx Adds centred label wrappers for matrix glyphs.
docs/​guides/​renderer-kit.md Documents label usage and insets.
docs/​guides/​develop-a-renderer.md Adds label alignment guidance.

Review effort: Balanced

…check

Polish step (c). Text centred by its line box sits a little high or low of
its chip, bar or button, by how its font's ascent, descent and cap height
compare, and differently in Chromium and WebKit. That is the user's capital-E
rule, so it moves into the kit and a renderer check.

- Kit `pk-label`: trims the text box to the capitals and the alphabetic
  baseline (`text-box: trim-both cap alphabetic`), then pads it back to its
  line height, so it keeps its size and whatever centres it centres the
  capitals. Extra room goes in `--pk-label-inset`. A label holding one
  identifier takes the identifier's font. Without `text-box` it is an
  ordinary line.
- The kit uses it in change pills and value changes, badges, status words
  and status tabs, group titles and meta, and the graph footer's buttons.
- `label-centring` (probe call `labels`): each HTML chip, bar or button (up to
  48px tall, painting a background or edges above and below, one line of its
  own text) must have as much room above its capitals as below its baseline,
  within half a pixel. The metrics come from the engine's own layout: each
  font's ascent and `1cap`, laid out once on a hidden line, because canvas
  metrics are rounded in WebKit and glyph ink differs between engines. A
  collapsed table rule counts half to each cell, and a box stretched by its
  row past its own line (a line number beside a wrapped line) isn't a label.
- `spacing` counts only a trimmed label's inset as spacing; the rest of its
  padding is its font's.

Violations found and fixed (Chromium and WebKit, desktop and mobile):
group headers, change pills, status tabs (kit); runtime-policy chips, head
rows and warnings; database headers, tags, value pills and column, key and
enum rows; text-diff line numbers, marks, text and captions; agentic-workflows
matrix cells and the stale-lock pill (its icon set the baseline);
code-statistics pills; api signatures (and their +/− mark, which WebKit put
on the trimmed line's top); gallery revision buttons; the graph footer.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek force-pushed the agorischek/cap-labels branch from b3e00b6 to 4da3a73 Compare November 23, 2026 00:07
agorischek and others added 2 commits November 22, 2026 17:27
…ks code values

- A one-line pk-label is at least its line height (its inset either side), with
  its trimmed text centred in it (align-content), padded half a pixel short of
  centring it alone. Its box no longer depends on the capitals an engine trims
  to or how it rounds the padding: Linux WebKit's left bands and the frames
  around them a fraction of a pixel off, and a changed region at a frame's foot
  then drew off-centre from its border (frames.spec, runtime-policy).
- labels.spec holds every one-line label's box to that height, in every
  scenario; spacing counts only its inset (its min-height less its line height).
- ValueChange's code prop marks its values as identifiers, so database no longer
  sets a font size itself (the SDK style lint's warning).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…e label keeps the UI font

Review follow-ups:
- A text fragment's rect is drawn (transformed) while the font's metrics are
  measured untransformed: the metrics and the surface's borders are scaled by
  the surface's drawn scale, and the gaps compared in its laid-out pixels, so a
  renderer that fits its drawing with a transform (database) measures true.
- labels.spec: a scaled stage stays clean; a label of mixed prose (words with a
  code span) keeps the UI font, as runtime-policy's warning notes do. Only a
  ValueChange marked code sets its values in mono (the CSS :only-child rule
  this replaced is gone).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@agorischek
agorischek merged commit 9ea961f into main Nov 23, 2026
51 checks passed
@agorischek
agorischek deleted the agorischek/cap-labels branch November 23, 2026 02:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants